package com.matt.order.controller;

import com.matt.order.dto.CustomerDto;
import com.matt.order.service.CustomerEnterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/customerEnter")
public class CustomerEnterController {

    @Autowired
    CustomerEnterService customerEnterService;

    @RequestMapping("/init")
    public String customerEnterInit(Model model) {
        return "order/customer-enter";
    }

    /**
     * 顾客信息录入
     * @param model
     * @return
     */
    @RequestMapping("/insertCustomerInfo")
    @ResponseBody
    public Map<String, Object> customerInfoInsert(Model model, CustomerDto customerEnterDto) {
        Map<String, Object> res = new HashMap<>();
        int result = customerEnterService.customerInfoInsert(customerEnterDto);
        if (result != 0) {
            res.put("code", 201);
        } else {
            res.put("code", 200);
        }
        return res;
    }
}
